{% extends 'muban.html' %}
{% block title %}新增商品导航{% endblock %}
{% block css %}{% endblock %}
{% block centent %}
<form class="layui-form layui-form-pane" action="">
    {% for obj in form %}
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">{{ obj.label }}</label>
            <div class="layui-input-inline">
                <!-- <input  placeholder="{{ obj.label }}" type="text" name="2"
                    autocomplete="off" class="layui-input"> -->
                    {{obj}}
            </div>
        </div>
    </div>
    {% endfor %}
    

    <div class="layui-form-item">
        <button class="layui-btn" lay-submit lay-filter="demo2">确认</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>

{% endblock %}
{% block js %}
<script>
    layui.use(['form'], function () {
        var form = layui.form;
        var layer = layui.layer;
        // 提交事件
        form.on('submit(demo2)', function (data) {
            var field = data.field; // 获取表单字段值

            // 显示填写结果，仅作演示用
            // layer.alert(JSON.stringify(field), {
            //     title: '当前填写的字段值'
            // });
            // return false
            // 此处可执行 Ajax 等操作
            // …
            const PARAMS = {
                "url": '/store/goods/create/nav/',
                "method": 'POST',
                "params": field
            }
            let response = YYAXIOS(PARAMS);
            response.then(res => {
                yy_layui.layui_alert("添加结果", res.data, 1)
                // layui.jquery(".layui-form")[0].reset();
            }).catch(err => {
                yy_layui.layui_alert("添加结果", err.response.data, 2)
            })
            layui.form.render();  
            return false; // 阻止默认 form 跳转
        });
    });
</script>

{% endblock %}